﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data;
using System.Web.UI.WebControls;

namespace HelpDesk
{
    public partial class Principal1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            QueryBuilder Consulta = new QueryBuilder();
            string sql;
            DataTable permisos = Consulta.EjecutarQuery("Select permisos from usuario where id_usuario = '" + Session["Usuario"] + "'");
            if (permisos.Rows[0].ItemArray[0].ToString() == "1")
            {
                sql = "SELECT distinct TICKET.ID_TICKET, TICKET.USUARIO_TICKET, TICKET.USUARIO_ADMIN, TICKET.TICKET_DESC, to_char(TICKET.FECHA_INICIO) AS FECHA, "
                       + " INFRAESTRUCTURA.DESCRIPCION AS INFRAESTRUCTURA, PROBLEMA.DESCRIPCION AS PROBLEMA, AREA_TRABAJO.DESCRIPCION AS AREA, "
                       + " PRIORIDAD.DESCRIPCION AS PRIORIDAD, PRIORIDAD.VALOR"//ppn 14/05/2011
                       + " FROM TICKET "
                       + " INNER JOIN PRIORIDAD ON TICKET.PRIORIDAD = PRIORIDAD.ID_PRIORIDAD "
                       + " INNER JOIN INFRAESTRUCTURA ON TICKET.INFRAESTRUCTURA = INFRAESTRUCTURA.ID_INFRAESTRUCTURA "
                       + " INNER JOIN PROBLEMA ON TICKET.PROBLEMA = PROBLEMA.ID_PROBLEMA "
                       + " INNER JOIN AREA_TRABAJO ON TICKET.AREA_ORIGEN = AREA_TRABAJO.ID_AREA WHERE (TICKET.STATUS = 'ENC') ORDER BY PRIORIDAD.VALOR ASC";
            }
            else
            {
                sql = "SELECT distinct TICKET.ID_TICKET, TICKET.USUARIO_TICKET, TICKET.USUARIO_ADMIN, TICKET.TICKET_DESC, to_char(TICKET.FECHA_INICIO) AS FECHA, "
                    + " INFRAESTRUCTURA.DESCRIPCION AS INFRAESTRUCTURA, PROBLEMA.DESCRIPCION AS PROBLEMA, AREA_TRABAJO.DESCRIPCION AS AREA, "
                    + " PRIORIDAD.DESCRIPCION as PRIORIDAD "
                    + " FROM TICKET "
                    + " INNER JOIN FLUJO_TICKET ON TICKET.ID_TICKET = FLUJO_TICKET.ID_TICKET "
                    + " INNER JOIN ASIG_PASO_FLUJO ON FLUJO_TICKET.ID_FLUJO = ASIG_PASO_FLUJO.FLUJO "
                    + " INNER JOIN PRIORIDAD ON TICKET.PRIORIDAD = PRIORIDAD.ID_PRIORIDAD "
                    + " INNER JOIN INFRAESTRUCTURA ON TICKET.INFRAESTRUCTURA = INFRAESTRUCTURA.ID_INFRAESTRUCTURA "
                    + " INNER JOIN PROBLEMA ON TICKET.PROBLEMA = PROBLEMA.ID_PROBLEMA "
                    + " INNER JOIN AREA_TRABAJO ON TICKET.AREA_ORIGEN = AREA_TRABAJO.ID_AREA "
                    + " WHERE (TICKET.STATUS = 'ASG' AND ASIG_PASO_FLUJO.USUARIO_ENCARGADO = '" + Session["Usuario"].ToString() + "') "
                    + " ORDER BY PRIORIDAD.VALOR ASC";
            }
           
            DataTable Principal = Consulta.EjecutarQuery(sql);
            GridView2.DataSource = Principal;
            GridView2.DataBind();

        }

    }
}
